using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MobileTDL
{
	public partial class SettingsForm : Form
	{
		private Settings _settings;

		public SettingsForm()
		{
			InitializeComponent();

			lstDisplayColumns.Items.Add(DisplayFieldType.Category);
			lstDisplayColumns.Items.Add(DisplayFieldType.DueDate);
			lstDisplayColumns.Items.Add(DisplayFieldType.PercentageDone);
			lstDisplayColumns.Items.Add(DisplayFieldType.Person);
			lstDisplayColumns.Items.Add(DisplayFieldType.Priority);
			lstDisplayColumns.Items.Add(DisplayFieldType.Risk);
			lstDisplayColumns.Items.Add(DisplayFieldType.Status);

			cboSortType.Items.Add(SortType.Position);
			cboSortType.Items.Add(SortType.Priority);
			cboSortType.Items.Add(SortType.Title);
			cboSortType.SelectedItem = SortType.Title;
		}

		public Settings Settings
		{
			get { return _settings; }
			set
			{
				_settings = value;
				if (_settings != null)
				{
					chkShowComments.Checked = _settings.ShowComments;
					chkShowDetails.Checked = _settings.ShowDetails;
					if (cboSortType.Items.Contains(_settings.SortType)) cboSortType.SelectedItem = _settings.SortType;
					ntxtUncompletePercentage.Value = _settings.UncompletePercentage;

					foreach (DisplayFieldType fieldType in _settings.DisplayFields)
					{
						lstSelectedDisplayColumns.Items.Add(fieldType);
					}
				}
			}
		}

		private void SettingsForm_Load(object sender, EventArgs e)
		{
		}

		private void btnAddAll_Click(object sender, EventArgs e)
		{
			lstSelectedDisplayColumns.Items.Clear();
			foreach (DisplayFieldType fieldType in lstDisplayColumns.Items) lstSelectedDisplayColumns.Items.Add(fieldType);
		}

		private void btnAdd_Click(object sender, EventArgs e)
		{
			if (lstDisplayColumns.SelectedItem != null) lstSelectedDisplayColumns.Items.Add(lstDisplayColumns.SelectedItem);
		}

		private void btnRemove_Click(object sender, EventArgs e)
		{
			if (lstSelectedDisplayColumns.SelectedItem != null) lstSelectedDisplayColumns.Items.Remove(lstSelectedDisplayColumns.SelectedItem);
		}

		private void btnRemoveAll_Click(object sender, EventArgs e)
		{
			lstSelectedDisplayColumns.Items.Clear();
		}

		private void miOK_Click(object sender, EventArgs e)
		{
			if (_settings != null)
			{
				_settings.ShowComments = chkShowComments.Checked;
				_settings.ShowDetails = chkShowDetails.Checked;
				_settings.SortType = (SortType)cboSortType.SelectedItem;
				_settings.UncompletePercentage = (int)ntxtUncompletePercentage.Value;
			}
			DialogResult = DialogResult.OK;
		}

		private void miCancel_Click(object sender, EventArgs e)
		{
			DialogResult = DialogResult.Cancel;
		}
	}
}